#include "log/log.h"
#include "unistd.h"
#include "pthread.h"

pthread_t t1;
pthread_t t2;

void *fun1(void *);
void *fun2(void *);

int main(void)
{
    // 创建线程
    if (pthread_create(&t1, NULL, fun1, NULL) != 0)
    {
        log_error("thread1 creat fail");
        return 0;
    }
    log_info("thread1 creat succes");
    if (pthread_create(&t2, NULL, fun2, NULL) != 0)
    {
        log_error("thread2 creat fail");
        return 0;
    }
    log_info("thread2 creat succes");
    sleep(5);
    pthread_cancel(t2);
    // 等待线程结束
    pthread_join(t1, NULL);
    pthread_join(t2, NULL);

    return 0;
}

void *fun1(void *)
{
    int count = 0;
    while (1)
    {
        sleep(1);
        count++;
        log_info("thread1....");
        if (count >= 10)
        {
            pthread_exit(NULL);
        }
    }
    return 0;
}
void *fun2(void *)
{
    while (1)
    {
        sleep(1);
        log_info("thread2....");
    }
    return 0;
}